package controller;

import com.alibaba.fastjson.JSON;
import entity.Dorm_rooms;
import service.Dorm_roomsService;
import service.impl.Dorm_roomsServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/Dorm_roomsController")
public class Dorm_roomsController extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        req.setCharacterEncoding("utf-8");
        HttpSession session = req.getSession(true);
        String op = req.getParameter("op");
        PrintWriter out=resp.getWriter();
        if(op.equals("buildingcx")){
            String id=req.getParameter("id");
            String roomnumberid=req.getParameter("roomnumberid");
            String floor=req.getParameter("floor");
            Dorm_roomsService dor=new Dorm_roomsServiceimpl();
            List<Dorm_rooms> list=null;
            try {
               list= dor.rooms(Integer.parseInt(id),roomnumberid,Integer.parseInt(floor));
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            out.write(JSON.toJSONString(list));
        }

    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req, resp);
    }
}
